@extends('admin.layout.app')
@section('title', '用户管理')

@section('nav')
    @include('admin.layout.nav', ['title'=> ['系统管理','添加用户']])
@endsection

@section('content')
    <div class="box box-primary" style="min-height: 300px;">
        <div class="box-header with-border">
            <h3 class="box-title">添加用户</h3>
        </div>
        <!-- /.box-header -->
        <form class="" action="" method="post" id="add-form">
            {{ csrf_field() }}
            <div class="box-body">
                <div class="form-group">
                    <label for="username">用户名：</label>
                    <input type="text" class="form-control" name="username" value="{{old('username')}}"  placeholder="">
                    @if($errors->has('username'))
                        <label class="control-label error" for="inputError1">{{$errors->first('username')}}</label>
                    @endif
                </div>
                <div class="form-group">
                    <label for="email">邮箱：</label>
                    <input type="email" class="form-control" name="email" value="{{old('email')}}"  placeholder="">
                    @if($errors->has('email'))
                        <label class="control-label error" for="inputError1">{{$errors->first('email')}}</label>
                    @endif
                </div>
                <div class="form-group">
                    <label for="pwd">密码：</label>
                    <input type="password" class="form-control" name="pwd" value="{{old('pwd')}}" id="pwd"  placeholder="">
                    @if($errors->has('pwd'))
                        <label class="control-label error" for="inputError1">{{$errors->first('pwd')}}</label>
                    @endif
                </div>
                <div class="form-group">
                    <label for="confirmpwd">确认密码：</label>
                    <input type="password" class="form-control"  name="confirmpwd" value="{{old('confirmpwd')}}" placeholder="">
                </div>
                <div class="form-group">
                    <label for="assign-roles[]">角色：</label>
                    <select multiple="multiple" name="assign-roles[]" id="assign-roles" class="form-control select2" style="width: 100%;">
                        @foreach($roles as $role)
                            <option value="{{$role->id}}">{{$role->display_name}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <!-- /.box-body -->

            <div class="box-footer">
                <input type="submit" class="btn btn-primary" value="提交">
                <a class="btn btn-default pull-right" href="javascript:window.history.back();">返回</a>
            </div>
        </form>

    </div>
@endsection

@section('style')
    <link rel="stylesheet" href="/lib/jquery.validation/1.14.0/validation.css">
    <link rel="stylesheet" href="/AdminLTE-2.4.2/bower_components/select2/select2.min.css">
    <style>

    </style>
@endsection

@section('js')
    <script type="text/javascript" src="/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript" src="/AdminLTE-2.4.2/bower_components/select2/select2.full.min.js"></script>
    <script >
        $(function(){
            $('#assign-roles').select2();
            $("#add-form").validate({
                rules: {
                    username: {
                        required: true,
                        minlength: 2
                    },
                    email: {
                        required: true,
                        email:true
                    },
                    pwd: {
                        required: true,
                        minlength: 5
                    },
                    confirmpwd: {
                        required: true,
                        equalTo: '#pwd'
                    }
                },
                messages: {
                    username: {
                        required: "请输入用户名",
                        minlength: "用户名必需由两个字母组成",
                        maxlength: '用户名不能超过50个字符'
                    },
                    email:{
                        required: "请输入邮箱",
                        email: "您输入的邮箱格式不正确"
                    },
                    pwd: {
                        required: "请输入密码",
                        minlength: "密码长度不能小于 6 个字母",
                        maxlenght: "密码不能超过20个字符"
                    },
                    confirmpwd: {
                        required: "请再次输入密码",
                        equalTo: '两次密码输入不一致！'
                    }
                },
                errorPlacement: function(error, element) {
                    error.appendTo(element.parent());
                }
            })
        })
    </script>
@endsection